<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
$_root  =   rtrim(dirname(rtrim($_SERVER['SCRIPT_NAME'],'/')),'/');
define('__ROOT__',  (($_root=='/' || $_root=='\\')?'':$_root));

// 应用公共文件

/**
 * 验证提交
 * @param $msg
 * @param string $status
 * @return \think\response\Json
 */
function ajax_info($msg, $status = '')
{
    $data['info'] = $msg;
    $status ? $data['status'] = $status : '';
    return json($data);
}

/**
* 导航面包屑
*/
function getCatpos($catid, $symbol = ' > ')
{
    $list = db('nav')->field('id,pid,name,model')->select();
    $list = getParents($list, $catid);
    $str = '';
    foreach ($list as $v) {
        $str .= '<a href=' . url($v['model'].'/index', ['navid' => $v['id']]) . '>' . $v['name'] . '</a>' . $symbol;
    }
    $str = '<a href=' . __ROOT__ . '>首页</a>' . $symbol . $str;
    return $str;
}
//获取某个分类的所有父分类
function getParents($categorys, $catid)
{
    $tree = [];
    foreach ($categorys as $item) {
        if ($item['id'] == $catid) {
            if ($item['pid'] > 0) {
                $tree = array_merge($tree, getParents($categorys, $item['pid']));
            }
            $tree[] = $item;
            break;
        }
    }
    return $tree;
}
